package cc.ruih.meizanchen;

import cc.ruih.meizanchen.bb.BBIndex;
import cc.ruih.meizanchen.mm.MMInfo;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;

/**
 * 设置页面
 * @author 郭瑞坡
 *
 */
public class Setting extends Activity{

	ImageButton arrow1;
	ImageButton arrow2;
	ImageButton arrow3;
	ImageButton arrow4;
	ImageButton arrow5;
	ImageButton arrow6;
	ImageButton arrow7;
	ImageButton arrow8;
	ImageButton arrow9;
	ImageButton arrow10;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting);
		ImageView headLogo = (ImageView) findViewById(R.id.headLogo);
		headLogo.setVisibility(View.GONE);
		ImageView setImage = (ImageView) findViewById(R.id.setting);
		setImage.setVisibility(View.GONE);
		arrow1 = (ImageButton) findViewById(R.id.arrow1);
		arrow2 = (ImageButton) findViewById(R.id.arrow2);
		arrow3 = (ImageButton) findViewById(R.id.arrow3);
		arrow4 = (ImageButton) findViewById(R.id.arrow4);
		arrow5 = (ImageButton) findViewById(R.id.arrow5);
		arrow6 = (ImageButton) findViewById(R.id.arrow6);
		arrow7 = (ImageButton) findViewById(R.id.arrow7);
		arrow8 = (ImageButton) findViewById(R.id.arrow8);
		arrow9 = (ImageButton) findViewById(R.id.arrow9);
		arrow10 = (ImageButton) findViewById(R.id.arrow10);
		arrow1.setOnClickListener(new ButtonClick());
		arrow2.setOnClickListener(new ButtonClick());
		arrow3.setOnClickListener(new ButtonClick());
		arrow4.setOnClickListener(new ButtonClick());
		arrow5.setOnClickListener(new ButtonClick());
		arrow6.setOnClickListener(new ButtonClick());
		arrow7.setOnClickListener(new ButtonClick());
		arrow8.setOnClickListener(new ButtonClick());
		arrow9.setOnClickListener(new ButtonClick());
		arrow10.setOnClickListener(new ButtonClick());
	}
	private class ButtonClick implements OnClickListener {
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.arrow1:
				new AlertDialog.Builder(Setting.this)
		           .setTitle("切换版本")		// 为对话框设置标题
		           .setMessage("您是否愿意切换到宝宝版？")		// 为对话框设置提示信息
		           .setPositiveButton("确定" , new DialogInterface.OnClickListener() {
		               @Override
		               public void onClick(DialogInterface dialog, int which) {
		            	   dialog.cancel();
		            	   Intent intent = new Intent();
		            	   SharedPreferences sharedPreferences2 = getSharedPreferences("bbinfo", Context.MODE_PRIVATE);
			   				String bbname = sharedPreferences2.getString("bbname", "");
			   				// 判断是否存储宝宝的信息
			   				if(bbname!=null&&bbname!=""&&bbname.length()>0){
			   					intent.setClass(Setting.this, BBIndex.class);		// 跳转到宝宝首页
			   				}else{
			   					intent.setClass(Setting.this, BBLogin.class);		// 跳转到宝宝档案页面
			   				}
			   				startActivity(intent);
		               }
		           })
		           .setNegativeButton("取消", new DialogInterface.OnClickListener() {
		               @Override
		               public void onClick(DialogInterface dialog, int which) {
		                   dialog.cancel();
		               }
		           })
		           .show();
				break;
			case R.id.arrow2:
				Intent intent = new Intent();
				intent.setClass(Setting.this, MMInfo.class);
   				startActivity(intent);
				break;
			case R.id.arrow3:
				Toast.makeText(getApplicationContext(),"功能未完善", Toast.LENGTH_SHORT).show();
				break;
			case R.id.arrow4:
				Toast.makeText(getApplicationContext(),"功能未完善", Toast.LENGTH_SHORT).show();
				break;
			case R.id.arrow5:
				new AlertDialog.Builder(Setting.this)
		           .setTitle("一键关注")		// 为对话框设置标题
		           .setMessage("您是否愿意关注美赞臣官方微博？")		// 为对话框设置提示信息
		           .setPositiveButton("确定" , new DialogInterface.OnClickListener() {
		               @Override
		               public void onClick(DialogInterface dialog, int which) {
		            	   dialog.cancel();
		            	   Toast.makeText(getApplicationContext(),"功能未完善", Toast.LENGTH_SHORT).show();
		               }
		           })
		           .setNegativeButton("取消", new DialogInterface.OnClickListener() {
		               @Override
		               public void onClick(DialogInterface dialog, int which) {
		                   dialog.cancel();
		               }
		           })
		           .show();
				break;
			case R.id.arrow6:
				new AlertDialog.Builder(Setting.this)
		           .setTitle("一键关注")		// 为对话框设置标题
		           .setMessage("您是否愿意关注美赞臣官方微博？")		// 为对话框设置提示信息
		           .setPositiveButton("确定" , new DialogInterface.OnClickListener() {
		               @Override
		               public void onClick(DialogInterface dialog, int which) {
		            	   dialog.cancel();
		            	   Toast.makeText(getApplicationContext(),"功能未完善", Toast.LENGTH_SHORT).show();
		               }
		           })
		           .setNegativeButton("取消", new DialogInterface.OnClickListener() {
		               @Override
		               public void onClick(DialogInterface dialog, int which) {
		                   dialog.cancel();
		               }
		           })
		           .show();
				break;
			case R.id.arrow7:
				// 跳转到美赞臣官网
				Uri uri = Uri.parse("http://www.meadjohnson.com.cn/");
                Intent mzc = new Intent(Intent.ACTION_VIEW,uri);
                startActivity(mzc);
				break;
			case R.id.arrow8:
				// 跳到使用条款页面
				Intent term = new Intent();
				term.setClass(Setting.this, Term.class);
   				startActivity(term);
				break;
			case R.id.arrow9:
				Toast.makeText(getApplicationContext(),"功能未完善", Toast.LENGTH_SHORT).show();
				break;
			case R.id.arrow10:
				// 跳到帮助页面页面
				Intent help = new Intent();
				help.setClass(Setting.this, Help.class);
   				startActivity(help);
				break;
			}
		}
	}

}
